package com.ufo.store.management.adapter;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.OvershootInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.ufo.store.management.BarApplication;
import com.ufo.store.management.R;
import com.ufo.store.management.entity.Isszmbalv3Member;
import com.ufo.store.management.entity.Isszmbalv3StockInfo;
import com.ufo.store.management.utils.GlideUtils;
import com.ufo.store.management.utils.Utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.ufo.store.management.BarApplication.mSavePictureDirPath;

/**
 *  作者：taoli on 2017/6/6 0006 16:25
 *  
 */
public class Isszmbalv3StockOrMemberRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Activity context = null;
    private int[] colors = new int[]{Color.parseColor("#59c7bc"), Color.parseColor("#f16d3d"), Color.parseColor("#f24980"), Color.parseColor("#ffa857")};
    private List<Object> mEntityInfoList = null;
    private Map<String, String> mIsszmbalv3StockTypeMap = null;
    private OnClickListener mListener = null;
    private Typeface tf;
    private int lastPosition = -1;
    private int longPressedIndex = -1;
    private RequestOptions isszmbalv3StockOptions;
    private RequestOptions isszmbalv3MemberOptions;

    public Isszmbalv3StockOrMemberRecyclerViewAdapter(Activity context, Map<String, String> map) {
        this.context = context;
        this.mEntityInfoList = new ArrayList<>();
        this.mIsszmbalv3StockTypeMap = map;
        tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");
        isszmbalv3StockOptions = new RequestOptions();
        isszmbalv3StockOptions.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
        isszmbalv3StockOptions.skipMemoryCache(false);
        isszmbalv3StockOptions.placeholder(R.drawable.ad7);
        isszmbalv3StockOptions.error(R.drawable.ad7);
        isszmbalv3MemberOptions = new RequestOptions();
        isszmbalv3MemberOptions.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
        isszmbalv3MemberOptions.skipMemoryCache(false);
        isszmbalv3MemberOptions.transform(new GlideUtils.GlideCircleTransform(context));
        isszmbalv3MemberOptions.placeholder(R.drawable.anastasia_circle);
        isszmbalv3MemberOptions.error(R.drawable.anastasia_circle);
    }

    public void insertData(Object data) {
        mEntityInfoList.add(data);
    }

    public void removeData(int pos) {
        mEntityInfoList.remove(pos);
    }

    public void clearData() {
        mEntityInfoList.clear();
    }

    public void setMap(Map<String, String> map) {
        mIsszmbalv3StockTypeMap = map;
    }

    public Map<String, String> getMap() {
        return mIsszmbalv3StockTypeMap;
    }

    public void setLongPressedIndex(int index) {
        longPressedIndex = index;
    }

    public int getLongPressedIndex() {
        return longPressedIndex;
    }

    public Object getItem(int pos) {
        Object info = mEntityInfoList.get(pos);
        return info;
    }

    @Override
    public int getItemViewType(int position) {
        Object obj = mEntityInfoList.get(position);
        if (obj instanceof Isszmbalv3StockInfo) {
            return 1;
        } else if (obj instanceof Isszmbalv3Member) {
            return 2;
        } else {
            return 3;
        }
    }

    @Override
    public void onViewDetachedFromWindow(RecyclerView.ViewHolder holder) {
        super.onViewDetachedFromWindow(holder);
        holder.itemView.clearAnimation();
    }

    /**
     * @desc 自定义动画
     * @author taoli
     * @time 2017/6/9 0009
     */
    private void setAnimation(View viewToAnimate, int position) {
        if (position > lastPosition) {
            Animation translateAnimation = new TranslateAnimation(0, 0, 100, 0);
            translateAnimation.setDuration(700);
            translateAnimation.setInterpolator(new OvershootInterpolator());
            viewToAnimate.setAnimation(translateAnimation);
            lastPosition = position;
        } else if (position < lastPosition) {
            Animation translateAnimation = new TranslateAnimation(0, 0, -100, 0);
            translateAnimation.setDuration(700);
            translateAnimation.setInterpolator(new OvershootInterpolator());
            viewToAnimate.setAnimation(translateAnimation);
            lastPosition = position;
        }
    }

    class Isszmbalv3StockRecyclerViewHolder extends RecyclerView.ViewHolder {
        ImageView stockIv;
        ImageView stockSecondaryIv;
        TextView stockNameTv;
        TextView stockTypeTv;
        TextView stockUnitTv;
        TextView stockBarcodeTv;
        TextView stockCostTv;
        TextView stockRetailPriceTv;
        TextView fuhao0Tv;
        TextView fuhao1Tv;
        ImageView menuIv;
        View maskV;
        TextView topTv;
        TextView bottomTv;

        public Isszmbalv3StockRecyclerViewHolder(View view) {
            super(view);
            stockIv = (ImageView) view.findViewById(R.id.stock_iv);
            stockSecondaryIv = (ImageView) view.findViewById(R.id.stock_secondary_iv);
            stockNameTv = (TextView) view.findViewById(R.id.stock_name_tv);
            stockTypeTv = (TextView) view.findViewById(R.id.stock_type_tv);
            stockUnitTv = (TextView) view.findViewById(R.id.stock_unit_tv);
            stockBarcodeTv = (TextView) view.findViewById(R.id.stock_barcode_tv);
            stockCostTv = (TextView) view.findViewById(R.id.stock_cost_tv);
            stockRetailPriceTv = (TextView) view.findViewById(R.id.stock_retail_price_tv);
            fuhao0Tv = (TextView) view.findViewById(R.id.fuhao0_tv);
            fuhao1Tv = (TextView) view.findViewById(R.id.fuhao1_tv);
            menuIv = (ImageView) view.findViewById(R.id.menu_iv);
            maskV = (View) view.findViewById(R.id.mask_v);
            topTv = (TextView) view.findViewById(R.id.top_iv);
            bottomTv = (TextView) view.findViewById(R.id.bottom_iv);
        }
    }

    class Isszmbalv3MemberRecyclerViewHolder extends RecyclerView.ViewHolder {
        TextView memberCatalogTv;
        ImageView memberIconIv;
        ImageView member_catalog_iv;
        TextView memberNameTv;
        TextView memberCardIdTv;
        TextView memberMobileTv;
        TextView memberPointTv;
        ImageView menuIv;
        View maskV;
        TextView topTv;
        TextView bottomTv;

        public Isszmbalv3MemberRecyclerViewHolder(View view) {
            super(view);
            memberCatalogTv = (TextView) view.findViewById(R.id.catalog_tv);
            memberIconIv = (ImageView) view.findViewById(R.id.member_icon_iv);
            member_catalog_iv = (ImageView) view.findViewById(R.id.member_catalog_iv);
            memberNameTv = (TextView) view.findViewById(R.id.member_name_tv);
            memberCardIdTv = (TextView) view.findViewById(R.id.member_cardid_tv);
            memberMobileTv = (TextView) view.findViewById(R.id.member_mobile_tv);
            memberPointTv = (TextView) view.findViewById(R.id.member_point_tv);
            menuIv = (ImageView) view.findViewById(R.id.menu_iv);
            maskV = (View) view.findViewById(R.id.mask_v);
            topTv = (TextView) view.findViewById(R.id.top_iv);
            bottomTv = (TextView) view.findViewById(R.id.bottom_iv);
        }
    }

    class OtherRecyclerViewHolder extends RecyclerView.ViewHolder {
        TextView memberCatalogTv;

        public OtherRecyclerViewHolder(View view) {
            super(view);
            memberCatalogTv = (TextView) view.findViewById(R.id.catalog);

        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder holder = null;
        if (viewType == 1) {
            holder = new Isszmbalv3StockRecyclerViewHolder(LayoutInflater.from(
                    this.context).inflate(R.layout.isszmbalv3_stock_recycleritem, parent,
                    false));
        } else if (viewType == 2) {
            holder = new Isszmbalv3MemberRecyclerViewHolder(LayoutInflater.from(
                    this.context).inflate(R.layout.isszmbalv3_member_recycleritem, parent,
                    false));
        } else if (viewType == 3) {
            holder = new OtherRecyclerViewHolder(LayoutInflater.from(
                    this.context).inflate(R.layout.other_recycleritem, parent,
                    false));
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
        final Object obj = mEntityInfoList.get(position);
        if (holder instanceof Isszmbalv3StockRecyclerViewHolder) {
            Isszmbalv3StockRecyclerViewHolder holder1 = (Isszmbalv3StockRecyclerViewHolder) holder;
            Isszmbalv3StockInfo isszmbalv3StockInfo = (Isszmbalv3StockInfo) obj;

            holder1.stockNameTv.setText(isszmbalv3StockInfo.item_name.trim() + " | " + isszmbalv3StockInfo.item_rem.trim());
            //holder1.stockNameTv.setTypeface(tf);
            if(isszmbalv3StockInfo.measure_flag.contains("0")) {
                holder1.stockUnitTv.setText("普通扫码");
            }else if(isszmbalv3StockInfo.measure_flag.contains("1") ){
                holder1.stockUnitTv.setText("散称计重");
            }

            if (isszmbalv3StockInfo.item_no == null || isszmbalv3StockInfo.item_no.length() == 0) {
                holder1.stockBarcodeTv.setText("条码");
              //  holder1.stockBarcodeTv.setTypeface(tf);
                holder1.stockBarcodeTv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);     // 设置中划线并加清晰 
            } else {
                holder1.stockBarcodeTv.setText(isszmbalv3StockInfo.item_no.trim());
              //  holder1.stockBarcodeTv.setTypeface(tf);
                holder1.stockBarcodeTv.getPaint().setFlags(0);              // 取消设置的的划线
            }

            if (mIsszmbalv3StockTypeMap == null) {
                holder1.stockTypeTv.setVisibility(View.GONE);
            } else {
                holder1.stockTypeTv.setVisibility(View.VISIBLE);
                if(!TextUtils.isEmpty(mIsszmbalv3StockTypeMap.get(isszmbalv3StockInfo.item_clsno)))
                    holder1.stockTypeTv.setText(mIsszmbalv3StockTypeMap.get(isszmbalv3StockInfo.item_clsno).trim());
            }

          //  holder1.fuhao0Tv.setTypeface(tf);
          //  holder1.fuhao1Tv.setTypeface(tf);
            holder1.stockRetailPriceTv.setText(String.valueOf(isszmbalv3StockInfo.sale_price));
          //  holder1.stockRetailPriceTv.setTypeface(tf);
            holder1.stockCostTv.setText(String.valueOf(isszmbalv3StockInfo.price));
          //  holder1.stockCostTv.setTypeface(tf);

            holder1.stockIv.setVisibility(View.VISIBLE);

            if (BarApplication.getInstance().mbStockDisplayCost) {
                holder1.stockCostTv.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
            } else {
                holder1.stockCostTv.setTransformationMethod(PasswordTransformationMethod.getInstance());
            }

            if (BarApplication.getInstance().mbStockDisplayPicture)
                getPicDesc(position, isszmbalv3StockInfo.item_no.trim(), holder1.stockIv, holder1.stockSecondaryIv);

            if (!holder1.menuIv.hasOnClickListeners()) {
                holder1.menuIv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getPosition();
                        mListener.onMenuClick(v, pos);
                    }
                });
            }

            if (!holder1.maskV.hasOnClickListeners()) {
                holder1.maskV.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getPosition();
                        mListener.onMaskClick(v, pos);
                    }
                });
            }

            if (!holder1.topTv.hasOnClickListeners()) {
                holder1.topTv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getPosition();
                        mListener.onDeleteClick(pos);
                    }
                });
            }

            if (!holder1.bottomTv.hasOnClickListeners()) {
                holder1.bottomTv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getPosition();
                        mListener.onDetailClick(pos);
                    }
                });
            }

            holder1.maskV.setVisibility(View.GONE);
            holder1.topTv.setVisibility(View.GONE);
            holder1.bottomTv.setVisibility(View.GONE);
            holder1.maskV.clearAnimation();
            holder1.topTv.clearAnimation();
            holder1.bottomTv.clearAnimation();


        } else if (holder instanceof Isszmbalv3MemberRecyclerViewHolder) {
            Isszmbalv3MemberRecyclerViewHolder holder1 = (Isszmbalv3MemberRecyclerViewHolder) holder;
            Isszmbalv3Member isszmbalv3MemberInfo = (Isszmbalv3Member) obj;

            holder1.memberNameTv.setText(isszmbalv3MemberInfo.memberName);
            //holder1.memberNameTv.setTypeface(tf);
            if (!TextUtils.isEmpty(isszmbalv3MemberInfo.memberMobile))
                holder1.memberMobileTv.setText(isszmbalv3MemberInfo.memberMobile);
            else if (!TextUtils.isEmpty(isszmbalv3MemberInfo.memberTel))
                holder1.memberMobileTv.setText(isszmbalv3MemberInfo.memberTel);
            //holder1.memberMobileTv.setTypeface(tf);
            holder1.memberCardIdTv.setText(isszmbalv3MemberInfo.memberCardNo);
            //holder1.memberCardIdTv.setTypeface(tf);
            holder1.memberPointTv.setText("累计积分" + String.valueOf((int) isszmbalv3MemberInfo.memberAccNum));
            holder1.memberPointTv.setTypeface(tf);

            if (position % 4 == 0) {
                holder1.memberMobileTv.setBackground(null);
                holder1.memberCardIdTv.setBackground(null);
            } else if (position % 4 == 1) {
                holder1.memberMobileTv.setBackground(null);
                holder1.memberCardIdTv.setBackground(null);
            } else if (position % 4 == 2) {
                holder1.memberMobileTv.setBackground(null);
                holder1.memberCardIdTv.setBackground(null);
            } else if (position % 4 == 3) {
                holder1.memberMobileTv.setBackground(null);
                holder1.memberCardIdTv.setBackground(null);
            }
            holder1.memberCatalogTv.setVisibility(View.GONE);

            String str = isszmbalv3MemberInfo.getSortLetters();

            if (!TextUtils.isEmpty(isszmbalv3MemberInfo.memberName)) {
                String s = isszmbalv3MemberInfo.memberName.substring(0, 0 + 1);
                if (s.getBytes().length >= 2) {
                    Drawable memberBmp = initLetterResources(s, position);
                    holder1.member_catalog_iv.setImageDrawable(memberBmp);
                } else {
                    Drawable memberBmp = initLetterResources(str, position);
                    holder1.member_catalog_iv.setImageDrawable(memberBmp);
                }
            } else {
                Drawable memberBmp = initLetterResources(str, position);
                holder1.member_catalog_iv.setImageDrawable(memberBmp);
            }

            if (BarApplication.getInstance().mbStockDisplayPicture)
                getPicDesc(position, isszmbalv3MemberInfo.memberCardId.trim(), holder1.memberIconIv, null);

            if (!holder1.menuIv.hasOnClickListeners()) {
                holder1.menuIv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getPosition();
                        mListener.onMenuClick(v, pos);
                    }
                });
            }

            if (!holder1.maskV.hasOnClickListeners()) {
                holder1.maskV.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getPosition();
                        mListener.onMaskClick(v, pos);
                    }
                });
            }

            if (!holder1.topTv.hasOnClickListeners()) {
                holder1.topTv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getPosition();
                        mListener.onDeleteClick(pos);
                    }
                });
            }

            if (!holder1.bottomTv.hasOnClickListeners()) {
                holder1.bottomTv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getPosition();
                        mListener.onDetailClick(pos);
                    }
                });
            }

            holder1.maskV.setVisibility(View.GONE);
            holder1.topTv.setVisibility(View.GONE);
            holder1.bottomTv.setVisibility(View.GONE);
            holder1.maskV.clearAnimation();
            holder1.topTv.clearAnimation();
            holder1.bottomTv.clearAnimation();
        }

        //进入动画
        setAnimation(holder.itemView, position);

        //点击事件
        if (mListener != null) {
            /**
             * 这里加了判断，itemViewHolder.itemView.hasOnClickListeners()
             * 目的是减少对象的创建，如果已经为view设置了click监听事件,就不用重复设置了
             * 不然每次调用onBindViewHolder方法，都会创建两个监听事件对象，增加了内存的开销
             */
            if (!holder.itemView.hasOnClickListeners()) {
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getPosition();
                        mListener.onItemClick(v, pos);
                    }
                });
                holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        int pos = holder.getPosition();
                        mListener.onItemLongClick(v, pos);
                        return true;
                    }
                });
            }
        }
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position, List payloads) {
        if (payloads.isEmpty()) {
            onBindViewHolder(holder, position);
        } else {
            if (holder instanceof Isszmbalv3StockRecyclerViewHolder) {
                String payload = (String) payloads.get(0);
                final Isszmbalv3StockRecyclerViewHolder holder1 = (Isszmbalv3StockRecyclerViewHolder) holder;
                if (payload.equals("recovery")) {
                    AnimationSet master_toappear_animation = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.master_toappear);
                    holder1.stockIv.startAnimation(master_toappear_animation);
                    AnimationSet secondary_todisappear_animation = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.secondary_todisappear);
                    holder1.stockSecondaryIv.startAnimation(secondary_todisappear_animation);
                } else if (payload.equals("exhibit")) {
                    AnimationSet master_todisappear_animation = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.master_todisappear);
                    holder1.stockIv.startAnimation(master_todisappear_animation);
                    AnimationSet secondary_toappear_animation = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.secondary_toappear);
                    holder1.stockSecondaryIv.startAnimation(secondary_toappear_animation);
                    holder1.stockSecondaryIv.setAlpha(1.0f);
                } else if (payload.equals("menu")) {
                    if (longPressedIndex != -1 && position == longPressedIndex) {
                        holder1.maskV.setVisibility(View.VISIBLE);
                        holder1.topTv.setVisibility(View.VISIBLE);
                        holder1.bottomTv.setVisibility(View.VISIBLE);
                        AnimationSet showAnimationSet = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.jump_toshow_anim);
                        holder1.maskV.startAnimation(showAnimationSet);
                        AnimationSet topAnimationSet = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.jump_totop_anim);
                        AnimationSet bottomAnimationSet = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.jump_tobottom_anim);
                        holder1.topTv.startAnimation(topAnimationSet);
                        holder1.bottomTv.startAnimation(bottomAnimationSet);
                    } else {
                        AnimationSet topToCenterAnimationSet = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.jump_toptocenter_anim);
                        topToCenterAnimationSet.setAnimationListener(new Animation.AnimationListener() {
                            @Override
                            public void onAnimationStart(Animation animation) {

                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {
                                holder1.topTv.setVisibility(View.GONE);
                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {

                            }
                        });
                        holder1.topTv.startAnimation(topToCenterAnimationSet);

                        AnimationSet bottomToCenterAnimationSet = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.jump_bottomtocenter_anim);
                        bottomToCenterAnimationSet.setAnimationListener(new Animation.AnimationListener() {
                            @Override
                            public void onAnimationStart(Animation animation) {

                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {
                                holder1.bottomTv.setVisibility(View.GONE);
                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {

                            }
                        });
                        holder1.bottomTv.startAnimation(bottomToCenterAnimationSet);

                        holder1.maskV.setVisibility(View.GONE);
                        holder1.maskV.clearAnimation();
                    }
                }
            } else if (holder instanceof Isszmbalv3MemberRecyclerViewHolder) {
                String payload = (String) payloads.get(0);
                final Isszmbalv3MemberRecyclerViewHolder holder1 = (Isszmbalv3MemberRecyclerViewHolder) holder;
                if (payload.equals("recovery")) {
                    ObjectAnimator mAnimatorCatalog = ObjectAnimator.ofFloat(holder1.member_catalog_iv, View.ROTATION_Y, 0, 90);
                    mAnimatorCatalog.setDuration(500);
                    mAnimatorCatalog.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {
                            holder1.member_catalog_iv.setAlpha(1f);
                            holder1.member_catalog_iv.setRotationY(0);
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            holder1.member_catalog_iv.setAlpha(0f);
                            holder1.member_catalog_iv.setRotationY(90);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    mAnimatorCatalog.start();

                    ObjectAnimator mAnimatorIcon = ObjectAnimator.ofFloat(holder1.memberIconIv, View.ROTATION_Y, 270, 360);
                    mAnimatorIcon.setDuration(500);
                    mAnimatorIcon.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {
                            holder1.memberIconIv.setAlpha(1f);
                            holder1.memberIconIv.setRotationY(270);
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            holder1.memberIconIv.setRotationY(0);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    mAnimatorIcon.setStartDelay(500);
                    mAnimatorIcon.start();
                } else if (payload.equals("exhibit")) {
                    ObjectAnimator mAnimatorIcon = ObjectAnimator.ofFloat(holder1.memberIconIv, View.ROTATION_Y, 0, 90);
                    mAnimatorIcon.setDuration(500);
                    mAnimatorIcon.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {
                            holder1.member_catalog_iv.setAlpha(0f);
                            holder1.member_catalog_iv.setRotationY(90);
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            holder1.memberIconIv.setAlpha(0f);
                            holder1.memberIconIv.setRotationY(270);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    mAnimatorIcon.start();

                    ObjectAnimator mAnimatorCatalog = ObjectAnimator.ofFloat(holder1.member_catalog_iv, View.ROTATION_Y, 270, 360);
                    mAnimatorCatalog.setDuration(500);
                    mAnimatorCatalog.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {
                            holder1.member_catalog_iv.setAlpha(1f);
                            holder1.member_catalog_iv.setRotationY(270);
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            holder1.member_catalog_iv.setRotationY(0);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    mAnimatorCatalog.setStartDelay(500);
                    mAnimatorCatalog.start();
                } else if (payload.equals("menu")) {
                    if (longPressedIndex != -1 && position == longPressedIndex) {
                        holder1.maskV.setVisibility(View.VISIBLE);
                        holder1.topTv.setVisibility(View.VISIBLE);
                        holder1.bottomTv.setVisibility(View.VISIBLE);
                        AnimationSet showAnimationSet = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.jump_toshow_anim);
                        holder1.maskV.startAnimation(showAnimationSet);
                        AnimationSet topAnimationSet = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.jump_totop_anim);
                        AnimationSet bottomAnimationSet = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.jump_tobottom_anim);
                        holder1.topTv.startAnimation(topAnimationSet);
                        holder1.bottomTv.startAnimation(bottomAnimationSet);
                    } else {
                        AnimationSet topToCenterAnimationSet = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.jump_toptocenter_anim);
                        topToCenterAnimationSet.setAnimationListener(new Animation.AnimationListener() {
                            @Override
                            public void onAnimationStart(Animation animation) {

                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {
                                holder1.topTv.setVisibility(View.GONE);
                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {

                            }
                        });
                        holder1.topTv.startAnimation(topToCenterAnimationSet);

                        AnimationSet bottomToCenterAnimationSet = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.jump_bottomtocenter_anim);
                        bottomToCenterAnimationSet.setAnimationListener(new Animation.AnimationListener() {
                            @Override
                            public void onAnimationStart(Animation animation) {

                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {
                                holder1.bottomTv.setVisibility(View.GONE);
                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {

                            }
                        });
                        holder1.bottomTv.startAnimation(bottomToCenterAnimationSet);
                        holder1.maskV.setVisibility(View.GONE);
                        holder1.maskV.clearAnimation();
                    }
                }
            }
        }
    }

    @Override
    public int getItemCount() {
        return mEntityInfoList.size();
    }

    public void setOnClickListener(OnClickListener l) {
        mListener = l;
    }

    public interface OnClickListener {
        void onDeleteClick(int position);

        void onDetailClick(int position);

        void onItemClick(View v, int position);

        void onItemLongClick(View v, int position);

        void onMenuClick(View v, int position);

        void onMaskClick(View v, int position);
    }

    private Drawable initLetterResources(String str, int position) {
        // 初始化画布
        int bitmapX = (int) Utils.dp2px(context.getResources(), 40);
        int bitmapY = (int) Utils.dp2px(context.getResources(), 40);
        Bitmap bitmapDrawable = Bitmap.createBitmap(bitmapX, bitmapY, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmapDrawable);
        //画圆
        Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);// 防抖动
        mPaint.setFilterBitmap(true);// 用来对Bitmap进行滤波处理，这样，当你选择Drawable时，会有抗锯
        mPaint.setColor(Color.parseColor("#ececec"));
        canvas.drawCircle(bitmapX / 2, bitmapX / 2, bitmapX / 2, mPaint);
        //画字母
        mPaint.setTextAlign(Paint.Align.CENTER);
        mPaint.setTypeface(Typeface.DEFAULT);
        mPaint.setColor(Color.WHITE);
        mPaint.setTextSize(Utils.dp2px(context.getResources(), 20));
        Paint.FontMetricsInt fontMetrics = mPaint.getFontMetricsInt();
        Rect dst = new Rect(0, 0, bitmapX, bitmapX);
        int baseline = dst.top + (dst.bottom - dst.top - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
        canvas.drawText(str, dst.centerX(), baseline, mPaint);
        canvas.save();
        return new BitmapDrawable(context.getResources(), bitmapDrawable);
    }

    private void getPicDesc(final int position, final String entityId, final ImageView iv, final ImageView ivCopy) {
        Object obj = mEntityInfoList.get(position);
        if (obj instanceof Isszmbalv3StockInfo) {
            String downloadRUL = BarApplication.Qiniu_BaseDownloadHost + BarApplication.mStoreName + "_" + "stockNo_" + entityId + ".jpg";

            RequestListener listener = new RequestListener<Drawable>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
                    return false;
                }

                @Override
                public boolean onResourceReady(Drawable drawable, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
                    //if (dataSource == DataSource.MEMORY_CACHE) {
                    //当图片位于内存缓存时，glide默认不会加载动画
                    iv.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fadein));
                    //}
                    return false;
                }
            };
//            Glide.with(context).load(downloadRUL).apply(isszmbalv3StockOptions).listener(listener).thumbnail(0.1f).into(iv);
//            Glide.with(context).load(downloadRUL).apply(isszmbalv3StockOptions).thumbnail(0.1f).into(ivCopy);
            String path = "file://" + mSavePictureDirPath + BarApplication.mStoreName + "_" + "stockNo_" + entityId + ".jpg";
            Glide.with(context).load(path).apply(isszmbalv3StockOptions).listener(listener).thumbnail(0.1f).into(iv);
            Glide.with(context).load(path).apply(isszmbalv3StockOptions).thumbnail(0.1f).into(ivCopy);
        } else if (obj instanceof Isszmbalv3Member) {
            String downloadRUL = BarApplication.Qiniu_BaseDownloadHost + BarApplication.mStoreName + "_" + "memberId_" + entityId + ".jpg";
            RequestListener listener = new RequestListener<Drawable>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
                    return false;
                }

                @Override
                public boolean onResourceReady(Drawable drawable, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
                    //if (dataSource == DataSource.MEMORY_CACHE) {
                    //当图片位于内存缓存时，glide默认不会加载动画
                    iv.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fadein));
                    //}
                    return false;
                }
            };
            //Glide.with(context).load(downloadRUL).apply(isszmbalv3MemberOptions).listener(listener).thumbnail(0.1f).into(iv);
            String path = "file://" + mSavePictureDirPath + BarApplication.mStoreName + "_" + "memberId_" + entityId + ".jpg";
            Glide.with(context).load(path).apply(isszmbalv3MemberOptions).listener(listener).thumbnail(0.1f).into(iv);
        }
    }
}
